
var menu = require("menu");
var pref = require("pref");
var find = require("find");
var tabs = require("tabs");
var show = require("show");


menu.attachMenuItem(onMenuItemClick);
pref.attachChangeHandler(pref.prefSearchDirectory, function (prefName) {
    var path = pref.getSearchDirectory();
    find.addToIndex(path);
});

function onMenuItemClick(selection)
{    
    var lang = pref.getDefaultLocale();
    var path = pref.getSearchDirectory();

    if (!path)
    {
        show.notifyNoSearchPath();
        return;
    }

    var output = find.findInFiles(selection, path, lang);
    tabs.showResult(output);
}